/**
 * 2
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-9-18 下午6:53
 */

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        double x0, y0, z0, vx, vy, vz, R;
        cin >> x0 >> y0 >> z0 >> vx >> vy >> vz >> R;

        double a = vx * vx + vy * vy + vz * vz;
        double b = 2 * (x0 * vx + y0 * vy + z0 * vz);
        double c = x0 * x0 + y0 * y0 + z0 * z0 - R * R;

        double d = b * b - 4 * a * c;
        if (d >= 0) {
            double sq = sqrt(d);
            double t1 = (sq - b) / (2 * a);
            double t2 = (-sq - b) / (2 * a);

            double res = min(t1, t2);
            if (res < 0) {
                res = max(t1, t2);
            }

            cout << res << endl;
        }
    }
}